<?php

namespace app\model;

use app\BaseModel;
use think\model\relation\HasMany;

/**
 * 地区
 */
class AreasModel extends BaseModel
{
    protected $name = 'areas';

    /**
     * 省级的用户-包含下级
     * @return HasMany
     */
    public function provinceAllUser(): HasMany
    {
        return $this->hasMany(UserModel::class, 'province_id')->where('role_mode','=',3);
    }

    /**
     * 市级的用户-包含下级
     * @return HasMany
     */
    public function cityAllUser(): HasMany
    {
        return $this->hasMany(UserModel::class, 'city_id')->where('role_mode','=',3);
    }

    /**
     * 区级的用户-包含下级
     * @return HasMany
     */
    public function areaAllUser(): HasMany
    {
        return $this->hasMany(UserModel::class, 'area_id')->where('role_mode','=',3);
    }

    /**
     * 省级的单位-包含下级
     * @return HasMany
     */
    public function provinceAllUnit(): HasMany
    {
        return $this->hasMany(UnitModel::class, 'province_id');
    }

    /**
     * 市级的单位-包含下级
     * @return HasMany
     */
    public function cityAllUnit(): HasMany
    {
        return $this->hasMany(UnitModel::class, 'city_id');
    }

    /**
     * 区级的单位-包含下级
     * @return HasMany
     */
    public function areaAllUnit(): HasMany
    {
        return $this->hasMany(UnitModel::class, 'area_id');
    }
}